﻿using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
using System;
using System.Reflection;

public class UseNeoLib : MonoBehaviour {

	public Transform rotateObj;
    string libPath = "D:/GitOSChina/LearnUnity2018/HotFixLibAsset/Assets/AssetBundle/x86_x64/neo.lib";
    
	Assembly assembly;
	IEnumerator Start()
	{
        var uwr = UnityWebRequest.GetAssetBundle(libPath);
        yield return uwr.SendWebRequest();

        AssetBundle ab = DownloadHandlerAssetBundle.GetContent(uwr);
        if (null == ab)
		{
			Debug.LogError("null bundle");
			yield break;
		}

		TextAsset asset = ab.LoadAsset<TextAsset>( "assets/library/neolib/neolib.bytes" );
		if (null == asset)
		{
			Debug.LogError("null neolib.bytes");
			yield break;
		}

		assembly = Assembly.Load( asset.bytes );
		Type[] types = assembly.GetTypes();
		foreach(Type t in types)
		{
			Debug.LogFormat("find Type({0}) in assembly", t.FullName);
		}

//		Assembly[] assLis = AppDomain.CurrentDomain.GetAssemblies();

		Type script = assembly.GetType("NeoLibRotateUtil");

		rotateObj.gameObject.AddComponent(script);
	}
}
